package com.dkm.biz.gl.domain;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.util.JSONStringer;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.entity.PO;
import com.dkm.base.db.persistence.entity.TreeType;
import com.dkm.biz.domain.AbstractDomain;
import com.dkm.biz.gl.persistence.dao.EavSetGroupAttrTreeDao;
import com.dkm.biz.gl.persistence.entity.EavSetGroupAttrTreePo;
import com.dkm.biz.gl.repository.EavSetGroupAttrTreeRepository;

/**
 * 对象功能:skg_eav_group_attr_tree 领域对象实体
 * 开发公司:SKG.COM
 * 开发人员:Yuki
 * 创建时间:2014-12-17 11:36:44
 */
@Service
@Scope("prototype")
public class EavSetGroupAttrTree extends AbstractDomain<String, EavSetGroupAttrTreePo>{
	 
	 private EavSetGroupAttrTreeDao eavSetGroupAttrTreeDao = null;
	 @Resource
	 EavSetGroupAttrTreeRepository eavSetGroupAttrTreeRepository;

	protected void init(){
		eavSetGroupAttrTreeDao = SpringHelper.getBean(EavSetGroupAttrTreeDao.class);
		setDao(eavSetGroupAttrTreeDao);
	}	
	
	public String loadsetGroupAttr(String setId) throws Exception{
		List<EavSetGroupAttrTreePo> eavSetGroupAttrTreePos=eavSetGroupAttrTreeRepository.findBySetId(setId);
		List<EavSetGroupAttrTreePo> returnList=new ArrayList<EavSetGroupAttrTreePo>();
		EavSetGroupAttrTreePo groupPo = new EavSetGroupAttrTreePo();
		String groupAttr = "";
		JSONStringer stringer = new JSONStringer();
		stringer.array();
		for(EavSetGroupAttrTreePo po:eavSetGroupAttrTreePos){
			if(StringUtils.isEmpty(po.getParentId())){
				stringer.object();
				stringer.key("id");
				stringer.value(po.getId());
				stringer.key("name");
				stringer.value(po.getName());
				
			}else{
				
			}
		}
		
		return groupAttr;
	}
	 
	private static void appendItem(JSONStringer stringer,PO po) {
		stringer.object();
		stringer.key("id");
		stringer.value(((TreeType<PO>)po).getId());
		stringer.key("name");
		stringer.value(((TreeType<PO>)po).getName());
		stringer.key("name");
		stringer.value(((TreeType<PO>)po).getName());
		if(((TreeType<PO>)po).getSubs().size()>0){
			//appendSub(stringer, ((TreeType<PO>)po).getSubs());
		}
		stringer.endObject();		
	}
	/*
	 * public static String toSimpleTreeData(List<? extends PO> pos) {
		JSONStringer stringer = new JSONStringer();
		stringer.array();
		for(PO po:pos){
			appendItem(stringer, po);
		}
		stringer.endArray();
		return stringer.toString();
	}
		
	
	
	private static void appendSub(JSONStringer stringer,List<PO> pos) {
		stringer.key("children");
		stringer.array();
		for(PO po:pos){
			appendItem(stringer, po);
		}
		stringer.endArray();
	}	
	 * */
	 
}
